<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    let arr1 = [1,2,3,4]
    let arr2 = [3,2,4,5,6]
    console.log (...arr1) // 展开数组
    let arr3 = [...arr1, ...arr2] //连接数组
    console.log (arr3)

    // 函数中使用
    function sum (...numbers) {
      return numbers.reduce ((preValue, currentValue) => {
        return preValue + currentValue
      })
    }
    console.log (sum (1,2,4,2))

    // 构造字面量对象时使用展开语法
    let person = {name: 'tom', age: 18}
    let person2 = {...person} //复制一个对象  展开运算符不能展开对象
    person.name = 'mary'
    console.log (person)
    console.log (person2)

    let person3 = {...person, name: 'jack', hobby: 'play'}
    console.log (person3)
  </script>
</body>
</html>